var mysql = require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost', //主机名
  user     : 'root',   //mysql的用户名
  password : '1234',   //MySQL的密码
  database : 'web25'   //要连接的数据库
});
 
connection.connect();
 
connection.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
  if (error) throw error;
  console.log('The solution is: ', results[0].solution);
});
function requestQuery(sql, sqlArr) {
    return new Promise((resolve, reject) => {
        connection.query(sql, sqlArr, (err, data) => {
            if (err) {
                reject(err)
            } else {
                resolve(data)
            }
        })
    })
};
//暴露
module.exports = {
    connection,
    requestQuery
}